package com.fcscs.cservice.ws.endpoint;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;

import com.fcscs.cservice.ws.schema.awuservice.GetAwuListRequest;
import com.fcscs.cservice.ws.schema.awuservice.GetAwuListResponse;
import com.fcscs.cservice.ws.schema.awuservice.SetAwuRequest;
import com.fcscs.cservice.ws.schema.awuservice.SetAwuResponse;
import com.fcscs.ecms.service.ECMSAwuManager;

/**
 * @author pvttinh
 * 
 */

@Endpoint
public class AwuServiceEndpoint {

	@Autowired
	private ECMSAwuManager awuMgr;
	
	/**
	 * 
	 * @param req
	 * @return
	 */
	@PayloadRoot(localPart = CServiceWSConstants.GET_AWU_LIST_RQ, namespace = CServiceWSConstants.AWU_SERVICE_NAMESPACE_URI)
	@ResponsePayload
	public GetAwuListResponse getAwuList(@RequestPayload GetAwuListRequest req) {

		GetAwuListResponse resp = new GetAwuListResponse();
		try{
			resp.setAwuCallList(this.awuMgr.getAwuList(req.getOrgId(), req.getPropId(), req.getGuestProfileId()));
			resp.setSuccess(true);
		}catch (Exception e) {
			// TODO: handle exception
			resp.setSuccess(false);
			resp.setErrorMessage(e.getMessage());
		}
		
		return resp;
	}
	
	@PayloadRoot(localPart = CServiceWSConstants.SET_AWU_RQ, namespace = CServiceWSConstants.AWU_SERVICE_NAMESPACE_URI)
	@ResponsePayload
	public SetAwuResponse setDnd(@RequestPayload SetAwuRequest req) {

		SetAwuResponse resp = new SetAwuResponse();
		try{
			resp.setAwuCall(this.awuMgr.setAwuCall(req.getAwuCall()));
			resp.setSuccess(true);
		}catch (Exception e) {
			// TODO: handle exception
			resp.setSuccess(false);
			resp.setErrorMessage(e.getMessage());
		}
		
		return resp;
	}
}
